#include "stdafx.h"
#include "Bitmap.h"
#include "RBMap.h"
#include "RBSet.h"
#include "RelatedFun.h"
#include <iostream>
#include <map>
#include <set>

void TestBitmap()
{
	WTB::CBitmap bitmap;
	int nSize;
	std::cin>>nSize;
	bitmap.InitBitmap(nSize);
	for (int i = 0 ; i != nSize; ++i)
	{
		std::cout<<bitmap.BitTestAndSet(i)<<" ";
		if ( (i + 1) % 10 == 0)
		{
			std::cout<<std::endl;
		}
	}
	std::cout<<std::endl;
	for (int i = 0 ; i != nSize; ++i)
	{	
		std::cout<<bitmap.GetBit(i)<<" ";
		if ( (i + 1) % 10 == 0)
		{
			std::cout<<std::endl;
		}
	}
	std::cout<<std::endl;
	for (int i = 0 ; i != nSize; ++i)
	{
		std::cout<<bitmap.BitTestAndReset(i)<<" ";
		if ( (i + 1) % 10 == 0)
		{
			std::cout<<std::endl;
		}
	}
	std::cout<<std::endl;
	for (int i = 0 ; i != nSize; ++i)
	{
		std::cout<<bitmap.GetBit(i)<<" ";
		if ( (i + 1) % 10 == 0)
		{
			std::cout<<std::endl;
		}
	}
	std::cout<<std::endl;
	bitmap.UnInitBitmap();
}

void TestRBMap()
{
	WTB::CRBMap<int,int> rbMap;
	//std::map<int,int> stdMap;
	int nCount;
	std::cin>>nCount;

	unsigned uBegTime = WTB::GetClock();

	for (int i = 0; i < nCount; ++i)
	{
		//stdMap.insert(std::pair<int,int>(i,i));
		rbMap.Insert(i,i);
	}

	unsigned uEndTime = WTB::GetClock();

	std::cout<<"take time: "<<uEndTime - uBegTime<<std::endl;

	//rbMap.Clear();

	WTB::CRBMap<int,int>::Iterator beg = rbMap.Begin();
	//std::map<int,int>::iterator beg = stdMap.begin();
	WTB::CRBMap<int,int>::Iterator end = rbMap.End();
	//std::map<int,int>::iterator end = stdMap.end();
	for (;beg != end; ++beg)
	{
		beg.GetValue();
		//beg->second;
	}

	uEndTime = WTB::GetClock();

	std::cout<<"take time: "<<uEndTime - uBegTime<<std::endl;

	for (int i = 0; i < nCount; ++i)
	{
		//stdMap.find(i);
		rbMap.Find(i);
	}

	uEndTime = WTB::GetClock();

	std::cout<<"take time: "<<uEndTime - uBegTime<<std::endl;

	for (int i = 0; i < nCount; ++i)
	{
		//stdMap.erase(i);
		rbMap.Erase(i);
	}

	uEndTime = WTB::GetClock();

	std::cout<<"take time: "<<uEndTime - uBegTime<<std::endl;
}

void TestRBSet()
{
	WTB::CRBSet<int> rbSet;
	std::set<int> stdSet;
	int nCount;
	std::cin>>nCount;

	unsigned uBegTime = WTB::GetClock();

	for (int i = 0; i < nCount; ++i)
	{
		stdSet.insert(i);
		//rbSet.Insert(i);
	}

	unsigned uEndTime = WTB::GetClock();

	std::cout<<"take time: "<<uEndTime - uBegTime<<std::endl;

	//rbSet.Clear();

	//WTB::CRBSet<int>::Iterator beg = rbSet.Begin();
	std::set<int>::iterator beg = stdSet.begin();
	//WTB::CRBSet<int>::Iterator end = rbSet.End();
	std::set<int>::iterator end = stdSet.end();
	for (;beg != end; ++beg)
	{
		*beg;
		//beg.GetKey();
	}

	uEndTime = WTB::GetClock();

	std::cout<<"take time: "<<uEndTime - uBegTime<<std::endl;

	for (int i = 0; i < nCount; ++i)
	{
		stdSet.find(i);
		//rbSet.Find(i);
	}

	uEndTime = WTB::GetClock();

	std::cout<<"take time: "<<uEndTime - uBegTime<<std::endl;


	for (int i = 0; i < nCount; ++i)
	{
		stdSet.erase(i);
		//rbSet.Erase(i);
	}

	uEndTime = WTB::GetClock();

	std::cout<<"take time: "<<uEndTime - uBegTime<<std::endl;
}

void main()
{
	//TestBitmap();
	//TestRBMap();
	TestRBSet();
	int test;
	std::cin>>test;
}
